package android.slc.box.core.scope;

import android.slc.box.core.notification.NotificationObserver;
import android.slc.box.core.virtual_android.Bundle;
import cn.hutool.core.util.SerializeUtil;

import java.util.List;

/**
 * 意图空间
 */
public class IntentScope extends ProtectedScopeImpl {
    public static String EVENT_LIST_REFRESH = "listRefresh";
    public static String EVENT_VIEW_RESULT = "viewResult";
    private List<String> stylesheets;
    private Bundle bundle;

    public IntentScope() {
    }

    public IntentScope(List<String> stylesheets, Bundle bundle) {
        this.stylesheets = stylesheets;
        this.bundle = bundle;
    }

    public void setStylesheets(List<String> stylesheets) {
        this.stylesheets = SerializeUtil.clone(stylesheets);
    }

    public List<String> getStylesheets() {
        return this.stylesheets;
    }

    public Bundle getBundle() {
        if (this.bundle == null) {
            this.bundle = new Bundle();
        }
        return this.bundle;
    }

    public void setBundle(Bundle bundle) {
        this.bundle = SerializeUtil.clone(bundle);
    }

    public void notifyRefreshList() {
        notifyRefreshList(null);
    }

    public void notifyRefreshList(Object payload) {
        publish(EVENT_LIST_REFRESH, payload);
    }

    public void subscribeRefreshList(NotificationObserver dataChangeListener) {
        subscribe(EVENT_LIST_REFRESH, dataChangeListener);
    }

    public void unSubscribeRefreshList(NotificationObserver dataChangeListener) {
        unsubscribe(EVENT_LIST_REFRESH, dataChangeListener);
    }

    public void notifyResultView(Object payload) {
        publish(EVENT_VIEW_RESULT, payload);
    }

    public void subscribeResultView(NotificationObserver dataChangeListener) {
        subscribe(EVENT_VIEW_RESULT, dataChangeListener);
    }


    public void unSubscribeResultView(NotificationObserver dataChangeListener) {
        unsubscribe(EVENT_VIEW_RESULT, dataChangeListener);
    }

}
